﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using WindowsGame1.DialogClasses;


namespace WindowsGame1.SpriteClasses
{
    public class NPC : AnimatedSprite
    {
        DialogComponent dialog;
        Script script;
        float speakingRadius;
        bool isTalking;
        string dialogName;
        float collisionRadius;


        public NPC(Game game, Texture2D texture, List<Animation> animations, DialogComponent dialog, Script script)
            : base(game, texture, animations)
        {
            speakingRadius = 80f;
            collisionRadius = 64f;
            this.dialog = dialog;
            this.script = script;
            dialog.Hide();
        }

        public bool IsTalking
        {
            get { return isTalking; }
        }
        
        public float SpeakingRadius
        {
            get { return speakingRadius; }
        }
        
        public string DialogName
        {
            get { return dialogName; }
            set { dialogName = value; }
        }
        
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            if (dialog.Enabled)
                dialog.Update(gameTime);
        }
        
        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
            if (dialog.Enabled)
                dialog.Draw(gameTime);
        }
        
        public void StartDialog(string dialogname)
        {
            if (script == null || dialog == null)
                return;
            dialog.npc = this;
            dialog.dialog = script[dialogname];
            isTalking = true;
        }
        
        public void StopDialog()
        {
            if (dialog == null)
                return;
            dialog.Hide();
            isTalking = false;
        }

        public float CollisionRadius
        {
            get { return collisionRadius; }
        }
    }
}